package com.android.functionmanagement.receiver;

import com.android.functionmanagement.globle.ConstantGloble;
import com.android.functionmanagement.globle.LogGloble;
import com.android.functionmanagement.service.DaemonService;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;
import android.os.Bundle;

public class BatteryBroadcastReciver extends BroadcastReceiver {

	private static final String TAG = "BatteryBroadcastReciver";

	@Override
	public void onReceive(Context context, Intent intent) {
		if (intent.getAction().equals(Intent.ACTION_BATTERY_LOW)) {
			// 得到系统当前电量
			Intent batteryIntent = context.getApplicationContext()
					.registerReceiver(null,
							new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
			int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL,
					-1);
			LogGloble.d(TAG, "ACTION_BATTERY_LOW:level="+level );
			Intent it = new Intent(context, DaemonService.class);
			it.putExtra(ConstantGloble.EXTRATYPE,
					ConstantGloble.ALARM_ACTION_BATTERY_DATA);
			Bundle extras = new Bundle();
			extras.putInt(ConstantGloble.ALARM_REQUEST_BATTERY_DATA, level);
			it.putExtras(extras);
			context.startService(it);
		}
	}

}
